﻿Public Class HMS_Security

#Region "Variables"
    Private con As String = ""
    Private len As Integer = 0
    Private position As Integer = 0
    Private len1 As Integer = 0
    Private reply As String = ""
    Private ascode As String = String.Empty
    ''''''''''''''''''''''''''''
    Private finalvalue As String = ""
    Private condition As Integer = 0
    Private finalint As Integer = 0
    Private mainloop1 As Integer = 0
    Private findme3 As String = ""
    Private dec As Integer = 0
    Private findme1 As Integer = 0
    Private decrypt As String = ""
#End Region

    Public Function setEncrypt(ByVal Txt As String) As String
        setEncrypt = ""
        Try
            con = ""
            len = Txt.Length
            position = 0
            For Me.len1 = 0 To Txt.Length
                If len1 = len Then Exit For
                reply = Txt.Chars(len1)
                ascode = Asc(reply)
                ascode = ascode * 20
                ascode = ascode / 2
                ascode = ascode - 100
                If position = 0 Then
                    con = con + CStr(ascode)
                    position = position + 1
                Else
                    con = con + "-" + CStr(ascode)
                End If
            Next
            setEncrypt = con
            Exit Function
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Function setDecrypt(ByVal strDecryptText As String) As String
        setDecrypt = ""
        Try
            con = strDecryptText
            finalvalue = ""
            condition = 0
            finalint = 0
            mainloop1 = 0
            findme3 = ""
            For Me.mainloop1 = 1 To con.Length
                If mainloop1 = con.Length Then Exit For
                dec = 0
                dec = InStr(mainloop1, con, "-", CompareMethod.Binary)
                finalint = mainloop1
                finalint = finalint - 1
                mainloop1 = dec
                If mainloop1 = 0 Then
                    For Me.findme1 = finalint To con.Length
                        If findme1 = con.Length Then Exit For
                        findme3 = findme3 + con.Chars(findme1)
                    Next
                    decrypt = ""
                    findme3 = findme3 + 100
                    findme3 = findme3 * 2
                    findme3 = findme3 / 20
                    decrypt = Chr(findme3)
                    finalvalue = finalvalue + decrypt
                    setDecrypt = finalvalue
                    Exit Function
                ElseIf finalint > condition Then
                    dec = dec - 1
                    For Me.findme1 = finalint To dec
                        If findme1 = dec Then Exit For
                        findme3 = findme3 + con.Chars(findme1)
                    Next
                    findme3 = findme3 + 100
                    findme3 = findme3 * 2
                    findme3 = findme3 / 20
                    decrypt = Chr(findme3)
                    findme3 = ""
                    finalvalue = finalvalue + decrypt
                Else
                    condition = finalint
                    dec = dec - 1
                    For Me.findme1 = 0 To dec
                        If findme1 = dec Then Exit For
                        findme3 = findme3 + con.Chars(findme1)
                    Next
                    findme3 = findme3 + 100
                    findme3 = findme3 * 2
                    findme3 = findme3 / 20
                    decrypt = Chr(findme3)
                    findme3 = ""
                    finalvalue = finalvalue + decrypt
                End If
            Next
        Catch ex As Exception
            Throw ex
        End Try
    End Function
End Class
